Files modified in the past should not trigger a fingerprint change
authorJake Goulding <jake.goulding@integer32.com>
Thu, 14 Jul 2016 23:17:08 +0000 (19:17 -0400)
committerJake Goulding <jake.goulding@integer32.com>
Wed, 27 Jul 2016 23:52:27 +0000 (19:52 -0400)
Previously, we would bail from the fingerprint computation if the old
and new mtimes had changed in *any* way. This caused some issues of
rebuilding with filesystems that do not preserve nanosecond
granularity (#2874).

src/cargo/ops/cargo_rustc/fingerprint.rs

index 2bef5a90774a8cd8b43c72e82f463b42f69e5c27..4b16a4a2ee64a8bbb02126c7741f0137cb5c3db8 100644 (file)
@@ -172,13 +172,21 @@ impl Fingerprint {
                           a, b)
                 }
             }
-            (&LocalFingerprint::MtimeBased(ref a, ref ap),
-             &LocalFingerprint::MtimeBased(ref b, ref bp)) => {
-                let a = a.0.lock().unwrap();
-                let b = b.0.lock().unwrap();
-                if *a != *b {
-                    bail!("mtime based components have changed: {:?} != {:?}, \
-                           paths are {:?} and {:?}", *a, *b, ap, bp)
+            (&LocalFingerprint::MtimeBased(ref on_disk_mtime, ref ap),
+             &LocalFingerprint::MtimeBased(ref previously_built_mtime, ref bp)) => {
+                let on_disk_mtime = on_disk_mtime.0.lock().unwrap();
+                let previously_built_mtime = previously_built_mtime.0.lock().unwrap();
+
+                let should_rebuild = match (*on_disk_mtime, *previously_built_mtime) {
+                    (None, None) => false,
+                    (Some(_), None) | (None, Some(_)) => true,
+                    (Some(on_disk), Some(previously_built)) => on_disk > previously_built,
+                };
+
+                if should_rebuild {
+                    bail!("mtime based components have changed: previously {:?} now {:?}, \
+                           paths are {:?} and {:?}",
+                          *previously_built_mtime, *on_disk_mtime, ap, bp)
                 }
             }
             _ => bail!("local fingerprint type has changed"),